package com.shop2cn.iapi.shenqisettlement.testcase;

import com.shop2cn.iapi.shenqisettlement.parameter.DistributionAgencyConfirmReceiptReq;
import com.shop2cn.iapi.shenqisettlement.service.DistributionAgencyConfirmReceiptCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.shenqisettlement.DistributorAgencyOfflineMonthBill;
import com.ymttest.database.sqlwapper.shenqisettlement.DistributorAgencyOfflineMonthBillWrapper;

import org.junit.*;
import org.junit.experimental.categories.Category;

/**
 * 根据国家获取汇率 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_DistributionAgencyConfirmReceipt {
	
	private static DistributionAgencyConfirmReceiptReq distributionAgencyConfirmReceiptReq;
	private static DistributionAgencyConfirmReceiptCall distributionAgencyConfirmReceiptCall;
	
	private DistributorAgencyOfflineMonthBillWrapper distributorAgencyOfflineMonthBillWrapper = new DistributorAgencyOfflineMonthBillWrapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("确认收款-线下结算");
	}

	@Before
	public void caseUp() {
		distributionAgencyConfirmReceiptReq = new DistributionAgencyConfirmReceiptReq();
		distributionAgencyConfirmReceiptCall = new DistributionAgencyConfirmReceiptCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(distributionAgencyConfirmReceiptCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public void verify() {

		DistributorAgencyOfflineMonthBill actualObject = distributorAgencyOfflineMonthBillWrapper
				.selectByPrimaryKey(distributionAgencyConfirmReceiptReq.getBillId());

		Logger.verifyEquals(1,
				actualObject.getReceived_confirmed(), "验证Received_confirmed");
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_DistributionAgencyConfirmReceipt_001() {
		Logger.start(true, "确认收款成功");
		try {
			
			distributorAgencyOfflineMonthBillWrapper.updatePaid(3L, 1);
			distributorAgencyOfflineMonthBillWrapper.updateReceived(3L, 0);

			distributionAgencyConfirmReceiptReq.setMerchantId(500011795L);
			distributionAgencyConfirmReceiptReq.setDistributorId(501565934L);
			distributionAgencyConfirmReceiptReq.setBillId(3L);
			
			distributionAgencyConfirmReceiptCall.setData(distributionAgencyConfirmReceiptReq);
			distributionAgencyConfirmReceiptCall.callService();
			
			this.verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_DistributionAgencyConfirmReceipt_002() {
		Logger.start(true, "已经确认收款的账单，无法再次确认收款");
		try {
			
			distributorAgencyOfflineMonthBillWrapper.updatePaid(3L, 1);
			distributorAgencyOfflineMonthBillWrapper.updateReceived(3L, 1);

			distributionAgencyConfirmReceiptReq.setMerchantId(500011795L);
			distributionAgencyConfirmReceiptReq.setDistributorId(501565934L);
			distributionAgencyConfirmReceiptReq.setBillId(3L);
			
			distributionAgencyConfirmReceiptCall.setData(distributionAgencyConfirmReceiptReq);
			distributionAgencyConfirmReceiptCall.callService();
			
			Logger.verifyEquals("该月账单已经确认过收款",
					distributionAgencyConfirmReceiptCall.getMsg(), "验证msg");
			Logger.verifyEquals(3,
					distributionAgencyConfirmReceiptCall.getErrorCode(),
					"验证resultCode");
			Logger.verifyEquals(false,
					distributionAgencyConfirmReceiptCall.getSuccess(),
					"验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_DistributionAgencyConfirmReceipt_003() {
		Logger.start(true, "未支付的账单，无法确认收款");
		try {
			
			distributorAgencyOfflineMonthBillWrapper.updatePaid(3L, 0);
			distributorAgencyOfflineMonthBillWrapper.updateReceived(3L, 0);

			distributionAgencyConfirmReceiptReq.setMerchantId(500011795L);
			distributionAgencyConfirmReceiptReq.setDistributorId(501565934L);
			distributionAgencyConfirmReceiptReq.setBillId(3L);
			
			distributionAgencyConfirmReceiptCall.setData(distributionAgencyConfirmReceiptReq);
			distributionAgencyConfirmReceiptCall.callService();
			
			Logger.verifyEquals("该月账单还未支付，无法确认收款",
					distributionAgencyConfirmReceiptCall.getMsg(), "验证msg");
			Logger.verifyEquals(3,
					distributionAgencyConfirmReceiptCall.getErrorCode(),
					"验证resultCode");
			Logger.verifyEquals(false,
					distributionAgencyConfirmReceiptCall.getSuccess(),
					"验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_DistributionAgencyConfirmReceipt_004() {
		Logger.start(true, "错误的商户，无权确认收款");
		try {
			
			distributorAgencyOfflineMonthBillWrapper.updatePaid(3L, 1);
			distributorAgencyOfflineMonthBillWrapper.updateReceived(3L, 0);

			distributionAgencyConfirmReceiptReq.setMerchantId(1L);
			distributionAgencyConfirmReceiptReq.setDistributorId(501565934L);
			distributionAgencyConfirmReceiptReq.setBillId(3L);
			
			distributionAgencyConfirmReceiptCall.setData(distributionAgencyConfirmReceiptReq);
			distributionAgencyConfirmReceiptCall.callService();
			
			Logger.verifyEquals("无权查看该账单",
					distributionAgencyConfirmReceiptCall.getMsg(), "验证msg");
			Logger.verifyEquals(3,
					distributionAgencyConfirmReceiptCall.getErrorCode(),
					"验证resultCode");
			Logger.verifyEquals(false,
					distributionAgencyConfirmReceiptCall.getSuccess(),
					"验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}